package cn.itcast.saveqq;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.HashMap;
import java.util.Map;

public class SQLiteSaveQQ {
    public static void insert(Context context, String account, String password){
        MyHelper myHelper = new MyHelper(context);
        SQLiteDatabase db = myHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("name", account);
        values.put("pwd", password);
        long id = db.insert("qquserinfo", null, values);
        db.close();
    }

    public static boolean validUserInfo(Context context, String account, String password){
        boolean rs = false;
        MyHelper myHelper = new MyHelper(context);
        SQLiteDatabase db = myHelper.getReadableDatabase();
        Cursor cursor = db.query("qquserinfo", null, "name=?",
                new String[]{account}, null, null, null);
        if(cursor.getCount() == 1){
            cursor.moveToFirst();
            @SuppressLint("Range") String pwd = cursor.getString(cursor.getColumnIndex("pwd"));
            if(pwd.equals(password)){
                rs = true;
            }
        }
        cursor.close();
        db.close();
        return rs;
    }
}
